﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.ObjectMapping;
using CPPProject.CPP.Dto;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPProject.CPP
{
    public class CPPOrderDtlAppService : AsyncCrudAppService<CPPOrderDtl, CPPOrderDtlDto, Guid, PagedResultRequestDto, CreateCPPOrderDtlDto, UpdateCPPOrderDtlDto>, ICPPOrderDtlAppService
    {
        private readonly IObjectMapper _objectMapper;
        public CPPOrderDtlAppService(
            IRepository<CPPOrderDtl, Guid> repository,
            IObjectMapper objectMapper) : base(repository)
        {
            _objectMapper = objectMapper;
        }
        /// <summary>
        /// 根据订单编号查询订单明细
        /// </summary>
        /// <param name="orderNum">订单编号</param>
        /// <returns></returns>
        public async Task<List<CPPOrderDtlDto>> GetById(string orderNum)
        {
            var obj = await Repository.GetAll().Where(o => o.OrderNum == orderNum).ToListAsync();
            return _objectMapper.Map<List<CPPOrderDtlDto>>(obj);
        }
        /// <summary>
        /// 批量删除订单明细
        /// </summary>
        /// <param name="id">标识Id</param>
        /// <returns></returns>
        public async Task BatchDeleteDtl(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                await Repository.DeleteAsync(o => id.Contains(o.Id.ToString()));
            }
        }
    }
}
